﻿//模块名称:JQuery上传文件控件
//功能描述:
//创建人:  Lam
//创建时间:2010年5月16日14:29:12
//修改描述:

//使用方法: 在JQuery框架下运行.故要先引用JQuery文件
//-------------------------前台------------------------------------
//在引用的页面 前台加上 CSS文件
/* 
  <link href="JQueryContrls/JqueryUploadify/uploadify.css" rel="stylesheet" type="text/css" />
 * 
 * 
//在引用的页面 前台加上 JS文件 
<script src="/JQueryContrls/JqueryUploadify/swfobject.js" type="text/javascript"></script>
<script src="/JQueryContrls/JqueryUploadify/jquery.uploadify.v2.1.0.min.js" type="text/javascript"></script> 

 * 说明: Uc_JQFileUpLoad1 为引用的自定义控件的ID名,需改相对应的ID名
<script>var JQFileUpLoadName = "<%=Uc_JQFileUpLoad1.ClientID%>";</script>
 
 说明:如果是引用邮件上传 引用以下JS:
<script src="/JQueryContrls/JqueryUploadify/Uc_JQMailFileUpLoad.js" type="text/javascript"></script>
 * 
 说明:若引用通用文件上传 引用以下JS:
 * <script src="/JQueryContrls/JqueryUploadify/Uc_JQFileUpLoad.js" type="text/javascript"></script>
*/
//在前台<form>中加上
/*
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
*/
//------------------------后台-------------------------------------


//在后台加上如下方法:  需引用命名空间using System.Web.Services; 
//注:使用该方法要保证引用页面有一个ScriptManager
/* 
    /// <summary>
    /// 删除一个文件
    /// </summary>
    /// <param name="FilePathName"></param>
    [WebMethod]
    public static int DeleteFile(string FilePathName)
    {
       return UploadFile.DeleteFile(FilePathName);
    }   
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using webnew.Common;
using webnew.Model;
using System.IO;

namespace webnew.UserControls
{
    public partial class Uc_JQFileUpLoad : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 获取上传文件的信息列表,根据实际业务修改
        /// </summary>
        /// <param name="tblName">对应的表名</param>
        /// <param name="tblID">对应表ID</param>
       /// <returns>返回Sys_FilesInfo 文件实体列表</returns>
        public List<Sys_FilesInfo> BindFileData(string tblName, string tblID)
        {
            List<Sys_FilesInfo> FileList = new List<Sys_FilesInfo>();
            if (hd_UpdateFileValue.Value != "")
            {
                string[] FilePathAndSize = hd_UpdateFileValue.Value.Split('#');
                foreach (string strPathandsize in FilePathAndSize)
                {
                    //截取有效的文件路径和大小字符串
                    string strGetPath = strPathandsize;
                    string strGetSize = strPathandsize;
                    strGetPath = strGetPath.Substring(0, strGetPath.LastIndexOf("_file"));
                    strGetSize = strGetSize.Substring(0, strGetSize.LastIndexOf("_file"));
                    //获取文件路径
                    string strPath = strGetPath.Substring(0, strGetPath.LastIndexOf("|"));
                    //获取文件大小
                    string strSize = strGetSize.Substring(strGetSize.LastIndexOf("|") + 1);
                    Model.Sys_FilesInfo model = new Model.Sys_FilesInfo();
                    model.FileName = Path.GetFileName(strPath);
                    model.FileType = strPath.Substring(strPath.LastIndexOf(".") + 1);
                    model.TblID = tblID;
                    model.FilePath = strPath.Substring(2);
                    model.FileLength = Convert.ToDecimal(strSize);
                    model.TblName = tblName;
                    model.FileHref = "<a href='" + model.FilePath + "'target=\"_blank\">" + UploadFile.NewFileToOldFile(model.FileName) + "</a>";
                    FileList.Add(model);
                }
            }
            else
            {
                FileList = null;
            }
            return FileList;
        }
      
    }
}